package com.gitee.wsl.collections.iterator

import com.gitee.wsl.func.Function

class CollectIterator<T, V>(
    private val iterator: Iterator<T>,
    private val function: Function<in T, out V>
) : Iterator<V> {

    constructor(iterable: Iterable<T>, function: Function<in T, out V>) : this(iterable.iterator(), function)

    override fun hasNext(): Boolean {
        return this.iterator.hasNext()
    }

     override fun next(): V {
        if (this.hasNext()) {
            return this.function(this.iterator.next())
        }
        throw NoSuchElementException()
    }
}
